package com.dahuyou.tryy.too.parse.clazz.file.clazzfile.constantpool.item;

import com.dahuyou.tryy.too.parse.clazz.file.clazzfile.ClassReader;
import com.dahuyou.tryy.too.parse.clazz.file.clazzfile.constantpool.ConstantInfo;
import com.dahuyou.tryy.too.parse.clazz.file.clazzfile.constantpool.ConstantPool;

import java.util.Map;

public class ConstantMemberRefInfo implements ConstantInfo {

    protected ConstantPool constantPool;
    protected int classIdx;
    private int nameAndTypeIdx;

    ConstantMemberRefInfo(ConstantPool constantPool) {
        this.constantPool = constantPool;
    }

    @Override
    public void readInfo(ClassReader reader) {
//        this.classIdx = reader.readUint16();
        this.classIdx = reader.readU2();
//        this.nameAndTypeIdx = reader.readUint16();
        this.nameAndTypeIdx = reader.readU2();
    }

    @Override
    public void showInfo() {

    }

    @Override
    public int tag() {
        return 0;
    }

    public String className() {
        return this.constantPool.getClassName(this.classIdx);
    }

    public Map<String, String> nameAndDescriptor() {
        return this.constantPool.getNameAndType(this.nameAndTypeIdx);
    }

}
